package com.itheima.youdianda.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.itheima.youdianda.common.R;
import com.itheima.youdianda.entity.YddLink;
import com.itheima.youdianda.service.YddLinkService;
import com.itheima.youdianda.util.MyPages;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2022-05-24
 */
@RestController
@RequestMapping("/ydd_link")
public class YddLinkController {
	@Autowired
	private YddLinkService yddLinkService;

	@GetMapping("/list")
	public R<MyPages<YddLink>> list(String type, @RequestParam(defaultValue = "1") String page, @RequestParam(defaultValue = "10") String limit){
		MyPages<YddLink> myPages = yddLinkService.listByPage(type, page, limit);
		return R.success(myPages);
	}

	@GetMapping("/rowInfo")
	public R<YddLink> rowInfo(int id){
		YddLink yddLink = yddLinkService.getById(id);
		return R.success(yddLink);
	}

	@PostMapping("/update")
	public R<String> update(@RequestBody YddLink yddLink){
		yddLinkService.updateById(yddLink);
		return R.success("修改成功!");
	}

	@GetMapping("/del")
	public R<YddLink> del(int id){
		YddLink yddLink = yddLinkService.getById(id);
		// 是默认数据,不可删除
		if("1".equals(yddLink.getDefault_data())){
			return R.success("系统默认数据，不允许删除",1000);
		}
		yddLinkService.removeById(id);
		return R.success(yddLink);
	}

	@PostMapping("/add")
	public R<String> add(@RequestBody YddLink yddLink){
		yddLinkService.save(yddLink);
		return R.success("新增成功!");
	}


}
